import React, { Component } from 'react'

const checkboxS = []

let arr = []

export default class Hobbies extends Component {
	
	state ={
		value: []
	}

	componentWillReceiveProps(newProps){
		// arr = (Array.isArray(newProps.value)) ? [...newProps.value] : newProps.value.splice(',')
   	// arr = newProps.value.splice('')

		console.log(newProps.value)
		
		this.setState({value: newProps.value})
	}

	handleAihao =(e)=>{
		// console.log(e.target.value)
		if(e.target.checked){
			checkboxS.push(e.target.value)
		}else{
			checkboxS.splice(checkboxS.indexOf(e.target.value), 1)
			
		}
		// console.log(checkboxS)
		this.props.onChange && this.props.onChange(checkboxS)
	}


  render() {

		const { options, onChange, aihao } = this.props

    return (
      <div>
				{
					options.map((item,index)=>(
						<label className="radio-inline" key={'ah'+ index} >
							<input type="checkbox" 
							onChange={this.handleAihao} 
							value={item.value}
							checked={this.state.value.includes(item.value)}
							/>{item.label}
					  </label>
					))
				}
					
      </div>
    )
  }
}
